<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/29 0029
  Time: 上午 10:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <title>订单提交</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">

    <style>
        .box-form{
            padding: 20px;
        }
        .layui-input{
            width: 300px;
        }
    </style>
</head>
<body>
<div class="box-form">
    <form class="layui-form "  method="post"  id="formid">

        <div class="layui-form-item">
            <label class="layui-form-label">订单号：</label>
            <div class="layui-input-block">
                <input type="text" name="orderid"  autocomplete="off" class="layui-input" value="${carOrder.orderid}">
            </div>
        </div>

        <hr>

        <div class="layui-form-item">
            <label class="layui-form-label">品牌型号：</label>
            <div class="layui-input-block">
                <input type="text" name="carbrand"   autocomplete="off" class="layui-input" value="${cars.carbrand}">
                <input type="hidden" name="carid" value="${cars.carid}">
                <input type="hidden" name="carcode" value="${cars.carcode}">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">车辆图片:</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                     <button type="button" class="layui-btn" id="upload"></button>
                    <input type="hidden" name="picture" id="picture" value="">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" STYLE="width: 100px;height: 100px" id="demo1"  <c:if test="">src="/down?path="</c:if>  >
                        <p id="uploadMsg" ></p>
                    </div>
                </div>
            </div>
        </div>


        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>取车地</legend>
        </fieldset>

        <div  class="layui-form-item ">
            <label class="layui-form-label">取车门店：</label>
            <div class="layui-input-block">
                <input type="text" name="btrentdept"  value="${carOrder.btrentdept}" autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">取车时间：</label>
            <div class="layui-input-block">
                <input type="text" name="readybttime"  id="readybttime"  autocomplete="off" class="layui-input"  value="<fmt:formatDate value="${carOrder.readybttime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>"/>
            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">详细地址：</label>
            <div class="layui-input-block">
                <input type="text" name="RentDetailAddress"  value="${carOrder.btrentdept}" autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>还车地</legend>
        </fieldset>

        <div  class="layui-form-item ">
            <label class="layui-form-label">还车门店：</label>
            <div class="layui-input-block">
                <input type="text" name="etrentdept" value="${carOrder.etrentdept}"  autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">还车时间：</label>
            <div class="layui-input-block">
                <input type="text" name="readettime"  id="readettime" autocomplete="off" class="layui-input" value="<fmt:formatDate value="${carOrder.readettime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>"/>
            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">详细地址：</label>
            <div class="layui-input-block">
                <input type="text" name="ReturnDetailAddress"  value="${carOrder.etrentdept}" autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">租期：</label>
            <div class="layui-input-block">
                <input type="text" name="rentDay" id="rentDay"  autocomplete="off" class="layui-input"  value=""/>
                <input type="hidden" name="dayprice"  id="dayprice" value="${cars.dayprice}" autocomplete="off" class="layui-input" />

            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">详细地址：</label>
            <div class="layui-input-block">
                <input type="text" name="ReturnDetailAddress"  value="${carOrder.etrentdept}" autocomplete="off" class="layui-input"/>
            </div>
        </div>


        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>费用明细:</legend>
        </fieldset>

        <div  class="layui-form-item ">
            <label class="layui-form-label">租赁费用：</label>
            <div class="layui-input-block">
                <input type="text" name="shouldrent" id="shouldrent"  autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <div  class="layui-form-item ">
            <label class="layui-form-label">基本保险：</label>
            <div class="layui-input-block">
                <input type="text" name="shouldbasic" value="${carOrder.shouldbasic}"   autocomplete="off" class="layui-input"/>
            </div>
        </div>


        <div  class="layui-form-item ">
            <label class="layui-form-label">总计：</label>
            <div class="layui-input-block">
                <input type="text" name="shouldtotal" value="${carOrder.shouldtotal}"    autocomplete="off" class="layui-input"/>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSubmit">确定还车</button>
                <a href="/returncar"><button type="button" class="layui-btn ">取消</button></a>
            </div>
        </div>
    </form>
</div>

</div>


<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script>

    layui.use(['upload','laydate','element','layer','form'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , laydate = layui.laydate
            , form = layui.form
            , element = layui.element
            , layer = layui.layer;

        var readybttime = new Date($("#readybttime").val()).getTime()
        var readettime = new Date($("#readettime").val()).getTime()
        var day = Math.ceil((readettime - readybttime)/(1000*60*60*24))

        $("#rentDay").val(day+"天")
        $("#shouldrent").val(Number($("#dayprice").val())*day)
        //监听提交
        form.on('submit(formSubmit)',function (data) {
            $.ajax({
                url:"/carOrder/updateOrderstate",
                type:"post",
                dataType:"json",
                data:{orderstate:4,orderid:data.field.orderid},
                success:function (rs) {

                        if(rs.code==1){
                            layer.msg("车辆审核通过",{time:1000,icon:1},function () {
                                location.href = "/returncar"
                            })
                        }

                }
            })
            return false
        })


        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload'
            , url: '/upload'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //上传成功
                if (res.code == 1){
                    $("#picture").val(res.data[0]);
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })

</script>
</body>
</html>

